<template>
  <footer class="footer" :class="{black:isBlack}">
    <div class="footer-logo">
      <img src="../assets/img/logo-little.png" alt="">
      <span>品牌中网</span>
    </div>
    <div class="footer-divide">
      <img src="../assets/img/divide-line.png" alt="">
    </div>
    <div class="footer-introduce-tel" v-if="introduceShow">
      <div>
        <span>客服电话：</span><a :href="'tel:'+tel" v-if="isPhone">{{tel}}</a><span class="phone" v-else>{{tel}}</span>
      </div>
      <div>
        <span>邮箱：</span><a>{{email}}</a>
      </div>
    </div>
    <div class="footer-tel" :class="{'footer-center': isWeiXin&&isPhone}" v-if="!introduceShow">
      <span>行业专员电话：<a :href="'tel:'+tel" v-if="isPhone">{{tel}}</a><span class="phone" v-else>{{tel}}</span></span>
      <span class="divide-line" v-if="!(isWeiXin&&isPhone)">|</span>
      <span class="back-to-top" v-if="!(isWeiXin&&isPhone)" @click="onHelpCenter">帮助中心</span>
      <span class="divide-line" v-if="!(isWeiXin&&isPhone)">|</span>
      <span class="back-to-top" v-if="!(isWeiXin&&isPhone)" @click="onBackToTop">回到顶部</span>
    </div>
    <div class="footer-line" v-if="!introduceShow"></div>
    <div class="footer-btns" v-if="(isWeiXin&&isPhone) && !introduceShow">
      <span class="footer-btn" @click="onAddBrand">品牌推荐</span>
      <span>|</span>
      <span class="footer-btn" @click="onFeedback">意见反馈</span>
      <span>|</span>
      <span class="footer-btn" @click="onHelpCenter">帮助中心</span>
      <span>|</span>
      <span class="footer-btn" @click="onBackToTop">回到顶部</span>
    </div>
    <div class="footer-info">
      <span>{{copyRight}}</span><br />
      <span>{{code}}</span>
    </div>
  </footer>
</template>

<script>
let addFlag = true
import { mapState } from 'vuex'
export default {
  props: {
    isBlack: {
      type: Boolean,
      default: false
    },
    introduceShow: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      isWeiXin: false,
      isPhone: false,
      copyRight: '',
      code: ''
    }
  },
  created() {
    this.isWeiXin = this.$getDeviceInfo().isWeiXin
    this.isPhone = this.$getDeviceInfo().isPhone
    addFlag = true
    this.getICP()
  },
  computed: {
    ...mapState({
      qq: s => s.serviceInfo.qq,
      tel: s => s.serviceInfo.tel,
      email: s => s.serviceInfo.email,
      wxqr: s => s.serviceInfo.wxqr,
    })
  },
  methods: {
    getICP() {
      this.$api.getICP().then(data => {
        this.copyRight = data.data.copyright
        this.code = data.data.record_no
      }).catch(() => {

      })
    },
    onAddBrand() {
      if (addFlag) {
        addFlag = false
        this.$router.push("/addbrand?catid=" + this.$route.query.catid + '&from=indexFooter&formPath=' + this.$route.path)
      } else {
        this.$toast.center('点击太频繁了，请稍候')
      }
    },
    onFeedback() {
      this.$router.push("/feedBack?catid=" + this.$route.query.catid + '&from=indexFooter&formPath=' + this.$route.path)
    },
    onHelpCenter() {
      this.$router.push("/helpCenter?catid=" + this.$route.query.catid)
    },
    onBackToTop() {
      window.scrollTo(0, 0)
    }
  }
}
</script>

<style scoped lang="scss">
.footer {
  width: 100%;
  padding: 0.37rem 0 1.35rem 0;
  background-color: #fff;
  .footer-logo {
    text-align: center;
    img {
      width: 0.3rem;
      height: auto;
      vertical-align: middle;
    }
    span {
      font-size: 0.29rem;
      margin-left: 0.15rem;
      color: #ad9f66;
      font-weight: 700;
      vertical-align: middle;
    }
  }
  .footer-divide {
    width: 5.9rem;
    margin: 0.2rem auto 0 auto;
    img {
      width: 100%;
      height: auto;
    }
  }
  .footer-tel {
    width: 6.4rem;
    display: flex;
    justify-content: space-between;
    margin: 0 auto;
    padding: 0.2rem 0;
    font-size: 0.26rem;
    text-align: center;
    color: #999;
    // border-bottom: 1px solid #dcdcdc;
    a {
      color: #739efb;
    }
    .divide-line {
      // display: inline-block;
      // margin: 0 0.4rem;
      color: #dcdcdc;
    }
    .back-to-top {
      color: #666;
      cursor: pointer;
    }
    .phone {
      color: #739efb;
    }
  }
  .footer-center {
    justify-content: center;
  }
  .footer-line {
    margin: 0 auto;
    width: 5.9rem;
    height: 1px;
    background-color: #dcdcdc;
  }
  .footer-introduce-tel {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 5.9rem;
    margin: 0 auto;
    padding: 0.2rem 0;
    font-size: 0.24rem;
    text-align: center;
    white-space: nowrap;
    color: #999;
    border-bottom: 1px solid #dcdcdc;
    a {
      color: #739efb;
    }
    .phone {
      color: #739efb;
    }
    .back-to-top {
      color: #666;
    }
  }
  .footer-btns {
    width: 5.9rem;
    height: 0.8rem;
    line-height: 0.8rem;
    border-bottom: 1px solid #dcdcdc;
    margin: auto;
    display: flex;
    justify-content: space-between;
    span {
      color: #dcdcdc;
    }
    .footer-btn {
      font-size: 0.26rem;
      color: #666;
      cursor: pointer;
    }
  }
  .footer-info {
    text-align: center;
    margin-top: 0.3rem;
    font-size: 0.24rem;
    color: #666;
    line-height: 0.4rem;
  }
  &.black {
    background-color: #202028;
    .footer-tel {
      a {
        color: #fff;
      }
    }
    .footer-btns {
      .footer-btn {
        color: #fff;
      }
    }
  }
}
</style>
